package com.aaa.ssm.controller;

import com.aaa.ssm.entity.Scenic;
import com.aaa.ssm.service.CommonFileHandlerService;
import com.aaa.ssm.service.ScenicService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;


@RestController
@RequestMapping("scenic")
public class ScenicController extends BaseController{

    @Resource
    private ScenicService scenicService;
    @Resource
    private CommonFileHandlerService commonFileHandlerService;
    @PostMapping("queryPage")
    public Result queryPage(@RequestBody Page<Scenic> page) {
        return success(scenicService.queryPage(page));
    }
    /**
     * 获取所有景区信息
     * @return
     */
    @GetMapping("queryAll")
    public Result queryAllScenic(){
        return success(scenicService.queryAll());
    }
    /**
     * 根据编号查询对象
     * @param id
     * @return 返回值
     */
    @GetMapping("queryById/{id}")
    public Result queryById(@PathVariable("id") int id){
        return success(scenicService.queryById(id));
    }
    /**
     * 文件上传对象  必须使用@RequestParam绑定上传对象,不可以少，少了上传不了
     * MultipartFile
     * @param file1
     * @return
     */
    @PostMapping("uploadFile")
    public Result uploadFile(@RequestParam MultipartFile file1){
        //调用封装的服务接口
        return success(commonFileHandlerService.uploadFile(file1,"scenic/pic/"));
    }
    /**
     * 新加部门
     * @param scenic 实体
     * @return 返回
     */
    @PostMapping("add")
    public Result add(@RequestBody Scenic scenic){
        return success(scenicService.add(scenic));
    }

    /**
     * 更新部门
     * @param scenic 实体
     * @return 返回
     */
    @PostMapping("update")
    public Result update(@RequestBody Scenic scenic){
        return success(scenicService.update(scenic));
    }

    /**
     * 删除部门
     * @param id 主键
     * @return 返回
     */
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
        return success(scenicService.deleteById(id));
    }
    /**
     * 排序查询类别
     * @param page
     * @return
     */
    @PostMapping("recommendShow")
    public Result recommendShow(@RequestBody Page<Scenic> page){
//        System.out.println(page+"------------参数");
        PageInfo pageInfo = scenicService.recommendShow(page);
        return success(pageInfo);
    }

    /**
     * 排序查询价钱
     * @param page
     * @return
     */
    @PostMapping("priceShow")
    public Result priceShow(@RequestBody Page<Scenic> page){
//        System.out.println(page+"------------参数");
        PageInfo pageInfo = scenicService.priceShow(page);

        return success(pageInfo);
    }

}
